package com.seavenois.alife2;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

/*************************************************/
/* An activity to activate and deactivate cheats */
/* Its a menu that saves SharedPreferences. ******/
/*************************************************/
public class CheatsFragment extends PreferenceFragment {

	CheckBoxPreference x10Selector, earningsSelector, debtSelector;
	SharedPreferences mySharedPreferences;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	  
		// Load the preferences from an XML resource
		addPreferencesFromResource(R.xml.menu_cheats);
		 
		//Assign elements
		x10Selector = (CheckBoxPreference) findPreference("cheats_x10");
		earningsSelector = (CheckBoxPreference) findPreference("cheats_earnings");
		debtSelector = (CheckBoxPreference) findPreference("cheats_debt");
		
		//Initial values
		mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
		updateChecks();

	}

	//Update style selector summary
	public void updateChecks(){
		boolean cheat10x = mySharedPreferences.getBoolean("cheats_x10", false);
		x10Selector.setChecked(cheat10x);
		boolean cheatEarnings = mySharedPreferences.getBoolean("cheats_earnings", false);
		x10Selector.setChecked(cheatEarnings);
		boolean cheatDebt = mySharedPreferences.getBoolean("cheats_debt", false);
		x10Selector.setChecked(cheatDebt);
	}
}
